package com.ruoyi.web.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.HomeLunbo;
import com.ruoyi.system.service.IHomeLunboService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 首页轮播图管理Controller
 * 
 * @author ruoyi
 * @date 2022-07-25
 */
@Controller
@RequestMapping("/system/lunbo")
public class HomeLunboController extends BaseController
{
    private String prefix = "system/lunbo";

    @Autowired
    private IHomeLunboService homeLunboService;

    @RequiresPermissions("system:lunbo:view")
    @GetMapping()
    public String lunbo()
    {
        return prefix + "/lunbo";
    }

    /**
     * 查询首页轮播图管理列表
     */
    @RequiresPermissions("system:lunbo:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(HomeLunbo homeLunbo)
    {
        startPage();
        List<HomeLunbo> list = homeLunboService.selectHomeLunboList(homeLunbo);
        return getDataTable(list);
    }

    /**
     * 导出首页轮播图管理列表
     */
    @RequiresPermissions("system:lunbo:export")
    @Log(title = "首页轮播图管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(HomeLunbo homeLunbo)
    {
        List<HomeLunbo> list = homeLunboService.selectHomeLunboList(homeLunbo);
        ExcelUtil<HomeLunbo> util = new ExcelUtil<HomeLunbo>(HomeLunbo.class);
        return util.exportExcel(list, "首页轮播图管理数据");
    }

    /**
     * 新增首页轮播图管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存首页轮播图管理
     */
    @RequiresPermissions("system:lunbo:add")
    @Log(title = "首页轮播图管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(HomeLunbo homeLunbo)
    {
        System.out.println("33333333333333333"+homeLunbo.getPictureSrc());
        return toAjax(homeLunboService.insertHomeLunbo(homeLunbo));
    }

    /**
     * 修改首页轮播图管理
     */
    @RequiresPermissions("system:lunbo:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        HomeLunbo homeLunbo = homeLunboService.selectHomeLunboById(id);
        mmap.put("homeLunbo", homeLunbo);
        return prefix + "/edit";
    }

    /**
     * 修改保存首页轮播图管理
     */
    @RequiresPermissions("system:lunbo:edit")
    @Log(title = "首页轮播图管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(HomeLunbo homeLunbo)
    {
        return toAjax(homeLunboService.updateHomeLunbo(homeLunbo));
    }

    /**
     * 删除首页轮播图管理
     */
    @RequiresPermissions("system:lunbo:remove")
    @Log(title = "首页轮播图管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(homeLunboService.deleteHomeLunboByIds(ids));
    }

    /**
     * 首页轮播图
     * @param homeLunbo
     * @return
     */
    @PostMapping("/mylist")
    @ResponseBody
    public AjaxResult getLunboList(HomeLunbo homeLunbo){
        List<HomeLunbo> list = homeLunboService.selectHomeLunboList(homeLunbo);
        return success(list);
    }
}
